/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bibliOnline.db;

import bibliOnline.util.details.ConstantDetails;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 *
 * @author luca
 */
public class ConstantManager {

    public static ConstantDetails get(String id) throws Exception {
        PreparedStatement statement;
        String sql;
        ConstantDetails constant;
        constant = new ConstantDetails();
        ResultSet result;

        sql = "SELECT ID, VALUE "
                + "FROM CONSTANT "
                + "WHERE    ID  =   ?";

        statement = DBConnection.prepareStatement(sql);
        statement.setString(1, id);
        result = statement.executeQuery();

        if (result.next() == true) {
            constant.setId(result.getString("ID"));
            constant.setValue(result.getLong("VALUE"));
        } else {
            throw new Exception("Costante inesistente");
        }

        result.close();
        statement.close();
        return constant;
    }
}
